package com.mindtalk.screen;

import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.muc.MultiUserChat;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;

import com.mindtalk.R;
import com.mindtalk.helper.ConnectionHelper;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class ChatList extends ListActivity  implements OnClickListener{
	
	/*
	 * Menampilkan Chat Yang Sedang Dilakukan
	 * */
	
	/*
	 * MultiUserChat 
	 * */
	MultiUserChat muc = null;
	
	
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.chatlistlayout);					
		Button submit = (Button)findViewById(R.id.btn_l_chatlistlayout_submit);
		submit.setOnClickListener(this);
		Intent i = this.getIntent();		
		String roomname = i.getCharArrayExtra("roomname").toString();
		MultiUserChat temp = ConnectionHelper.mucData.get(roomname);
		if(temp!=null){
			this.muc = temp;
		}		
	}



	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v.getId() == R.id.btn_l_chatlistlayout_submit){
			String text = ((EditText)findViewById(R.id.et_l_chatlistlayout_chat)).getText().toString();
			try {
				muc.sendMessage(text);
			} catch (XMPPException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}
